<!-- 编辑新增对话框js,如有需要请导出到对应的对话框js文件中 -->
var userRoleDialog = function(){
    var modal = $('#userRoleDialog');
    var saveUrl = _CTX_ + '/core/account/saveRoles';
    var form = modal.find("form");
    var _callback;
    var btnSave = modal.find("#btnSave");

    var _datasetKit = _GetDatasetKit("RoleList");
    _datasetKit.initSelect(modal.find("select#roleIds"), "RoleList");

    modal.find("select#roleIds").bootstrapDualListbox({
        "filterTextClear" : "显示全部",
        "filterPlaceHolder" : "过滤条件",
        "moveAllLabel" : "选择全部",
        "removeAllLabel" : "移除全部",
        "infoText" : "显示全部 {0} 条",
        "infoTextFiltered" : "过滤后显示 {0} 条, 总共 {1} 条",
        "infoTextEmpty" : "空列表",
        "selectorMinimalHeight" : 200
    });

    btnSave.click(function(){
        form.ajaxSubmit({
            url:saveUrl,
            type:"POST",
            dataType:"json",
            cache:false,
            success:function(ret){
                if(ret.state == "ok"){
                    if(_callback && typeof(_callback)=='function'){
                        result = _callback(ret);
                        if(typeof(result) == 'undefined' || result != false){
                            modal.modal('hide');
                        }
                    }else{
                        modal.modal('hide');
                    }
                }else{
                    alert(ret.msg);
                }
            }
        });
    });

    return {
        show: function (entity, options) {
            if(options && options.title){
                modal.find(".modal-title").html(options.title);
            }
            if(options && options.callback){
                _callback = options.callback;
            }
            _FormKit_.bindData(form,entity,null,options && options.readOnly);
            modal.find("select#roleIds").bootstrapDualListbox('refresh');
            modal.modal('show');
        }
    }

}();